package cn.fl.spl.controller;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.spl.service.ISplOpLogRecService;
import cn.fl.spl.service.ISplRelOpLogService;
import cn.fl.spl.transform.SplRelOpLogVOTransform;
import cn.fl.spl.vo.SplRelOpLogVO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import fl.constant.facade.framework.constant.BusinessIdConstant;
import fl.flow.facade.flow.api.IFlowQueryApiService;
import fl.flow.facade.flow.condition.SysFlowSHQueryCondition;
import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.SysFlowSHDTO;
import fl.mongo.facade.base.page.PaginationVo;
import fl.mongo.facade.spl.condition.SplOpLogRecQC;
import fl.mongo.facade.spl.dto.SplOpLogRecDTO;
import fl.spl.facade.framework.constant.DictionaryConstant;
import fl.spl.facade.framework.constant.SplSystemConstant;
import fl.spl.facade.framework.enums.FlowStartRelInfoCfgEnum;
import fl.spl.facade.framework.enums.SplRelLogBizTypCdNum;
import fl.spl.facade.store.condition.SplRelOpLogQC;
import fl.spl.facade.store.dto.SplRelOpLogDTO;

import net.sf.json.JSONArray;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Description: 供应商相关操作日志记录表 控制层
 */
@Controller
@RequestMapping("/spl/splRelOpLog")
public class SplRelOpLogController extends BaseController {

	/**
	 * SplRelOpLog 服务层BEAN
	 */
	@Autowired
	private ISplRelOpLogService splRelOpLogService;

	@Autowired
	private ISplOpLogRecService splOpLogRecService;

	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;

	@Autowired
	private IFlowQueryApiService flowQueryApiService;

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();

		ModelAndView view = new ModelAndView("spl/splRelOpLog/splRelOpLogList");

		String dataId = request.getParameter("dataId");
		view.addObject("dataId", dataId);
		String bizTypCd = request.getParameter("bizTypCd");
		view.addObject("bizTypCd", bizTypCd);

		Long endTm = System.currentTimeMillis();
		BaseLogUtils.newWebLogger("加载列表页面.耗时：" + (endTm-startTm)).setLogOperType(LogOperEnum.REQ)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
				.setWarning(false)
				.info();
		return view;
	}
	
	/**
	 * 到新增修改页面
	 */
	@RequestMapping(value = "/toAddPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {

		ModelAndView view = new ModelAndView("store/splRelOpLog/splRelOpLogAdd");

		String dataId = request.getParameter("dataId");
		view.addObject("dataId", dataId);
		String bizTypCd = request.getParameter("bizTypCd");
		view.addObject("bizTypCd", bizTypCd);
		//必填联系人类型
		List<SysDictionaryDTO> splOpTypCds = this.sysDictionaryApiService.searchGroupAll(SplSystemConstant.SPL_SYS_CD,SplSystemConstant.DEFAULT_ORG_CD, DictionaryConstant.SPL_OP_TYP_CD);
		List<KeyValueVO> opTypCd = null ;
		if(CollectionUtils.isNotEmpty(splOpTypCds)){
			opTypCd = new ArrayList<>(splOpTypCds.size());
			for(SysDictionaryDTO dto : splOpTypCds){
				if(BaseConstant.IS_YESNO_YES == dto.getIsSysDef()){
					KeyValueVO keyValueVO = new KeyValueVO();
					keyValueVO.setKey(dto.getCode());
					keyValueVO.setValue(dto.getCodeNm());
					opTypCd.add(keyValueVO);
				}
			}
		}
		view.addObject("opTypCd", JSON.toJSON(opTypCd));

		List<KeyValueVO> signDesc = this.sysDictionaryApiService.getKvList(DictionaryConstant.SPL_SIGN_DESC_CD,SplSystemConstant.SPL_SYS_CD,SplSystemConstant.DEFAULT_ORG_CD);
		view.addObject("signDesc", JSON.toJSON(signDesc));

		return view;
	}

	/**
	 * 到修改页面
	 */
	@RequestMapping(value = "/toModifyPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {

		ModelAndView view = new ModelAndView("store/splRelOpLog/splRelOpLogModify");

		String dataId = request.getParameter("dataId");
		view.addObject("dataId", dataId);
		String bizTypCd = request.getParameter("bizTypCd");
		view.addObject("bizTypCd", bizTypCd);
		//必填联系人类型
		List<SysDictionaryDTO> splOpTypCds = this.sysDictionaryApiService.searchGroupAll(SplSystemConstant.SPL_SYS_CD,SplSystemConstant.DEFAULT_ORG_CD, DictionaryConstant.SPL_OP_TYP_CD);
		List<KeyValueVO> opTypCd = null ;
		if(CollectionUtils.isNotEmpty(splOpTypCds)){
			opTypCd = new ArrayList<>(splOpTypCds.size());
			for(SysDictionaryDTO dto : splOpTypCds){
				if(BaseConstant.IS_YESNO_YES == dto.getIsSysDef()){
					KeyValueVO keyValueVO = new KeyValueVO();
					keyValueVO.setKey(dto.getCode());
					keyValueVO.setValue(dto.getCodeNm());
					opTypCd.add(keyValueVO);
				}
			}
		}
		view.addObject("opTypCd", JSON.toJSON(opTypCd));

		List<KeyValueVO> signDesc = this.sysDictionaryApiService.getKvList(DictionaryConstant.SPL_SIGN_DESC_CD,SplSystemConstant.SPL_SYS_CD,SplSystemConstant.DEFAULT_ORG_CD);
		view.addObject("signDesc", JSON.toJSON(signDesc));


		return view;
	}
	
	/**
	 * 到详情页面
	 */
	@RequestMapping(value = "/toDetailPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {

		String id = request.getParameter("id");
		ModelAndView view = new ModelAndView("store/splRelOpLog/splRelOpLogDetail");
		view.addObject("id", id);
		
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET ,RequestMethod.POST })
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		ListPageVO<SplRelOpLogVO> listPage = null;
		
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String dataId = request.getParameter("dataId");
		String bizTypCd = request.getParameter("bizTypCd");
		if (StringUtils.isEmpty(dataId) || StringUtils.isEmpty(bizTypCd)) {
			listPage = new ListPageVO<SplRelOpLogVO>(new ArrayList<SplRelOpLogVO>(),0);
			return listPage;
		}
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		PaginationVo paginationVo = new PaginationVo();
		SplOpLogRecQC condition = new SplOpLogRecQC();
		condition.setDataId(Long.valueOf(dataId));
		condition.setIsDel(BaseConstant.IS_YESNO_NO);
		condition.setOpObjTyp(bizTypCd);
		paginationVo.setCondition(condition);

		PaginationVo searchListPage = this.splOpLogRecService.searchListPage(paginationVo);
		if (null == searchListPage) {
			listPage = new ListPageVO<SplRelOpLogVO>(new ArrayList<SplRelOpLogVO>(),0);
			return listPage;
		}

		List<SplOpLogRecDTO> datas = (List<SplOpLogRecDTO>) searchListPage.getDatas();

		if (CollectionUtils.isEmpty(datas)) {
			listPage = new ListPageVO<SplRelOpLogVO>(new ArrayList<SplRelOpLogVO>(),0);
			return listPage;
		}
		/*SplRelOpLogQC qc = new SplRelOpLogQC();
		qc.setDataId(Long.valueOf(dataId));
		qc.setBizTypCd(bizTypCd);
		qc.setIsDel(BaseConstant.IS_YESNO_NO);
		qc.setIsValid(BaseConstant.IS_YESNO_YES);
		qc.setIsRiskSign(BaseConstant.IS_YESNO_YES);
		page.setCondition(qc);

		//TODO SOMETHING

		Pager pager = this.splRelOpLogService.searchListPage(page);
		List<SplRelOpLogVO> list = (List<SplRelOpLogVO>) pager.getResultList();*/

		List<SplRelOpLogVO> list = new ArrayList<SplRelOpLogVO>();
		for (SplOpLogRecDTO splOpLogRecDTO : datas ) {
			SplRelOpLogVO splRelOpLogVO = new SplRelOpLogVO();
			splRelOpLogVO.setCrtUsrName(splOpLogRecDTO.getCrtUsrNm());
			splRelOpLogVO.setCrtTm(splOpLogRecDTO.getCrtTm());
			splRelOpLogVO.setOpDesc(splOpLogRecDTO.getOpDesc());
			splRelOpLogVO.setOpTypCd(splOpLogRecDTO.getOpTypCd());
			splRelOpLogVO.setSignDesc(splOpLogRecDTO.getSignDesc());
			if(StringUtils.isNotEmpty(splOpLogRecDTO.getIsRiskSign()) && splOpLogRecDTO.getIsRiskSign().equals(BaseConstant.IS_YESNO_YES)){
				splRelOpLogVO.setRiskSign("风险标记");
			}else{
				splRelOpLogVO.setRiskSign("非风险标记");
			}
			list.add(splRelOpLogVO);
		}

		if(CollectionUtils.isNotEmpty(list)){

			// 查询数据字典
			Map<String, String> opTypCdMap = this.sysDictionaryApiService.searchGroupToMap(SplSystemConstant.SPL_SYS_CD,
					SplSystemConstant.DEFAULT_ORG_CD, DictionaryConstant.SPL_OP_TYP_CD);

			// 查询数据字典
			Map<String, String> signDescMap = this.sysDictionaryApiService.searchGroupToMap(SplSystemConstant.SPL_SYS_CD,
					SplSystemConstant.DEFAULT_ORG_CD, DictionaryConstant.SPL_SIGN_DESC_CD);

			for (SplRelOpLogVO splRelOpLogVO: list) {
				splRelOpLogVO.setOpTypCdNm(opTypCdMap.get(splRelOpLogVO.getOpTypCd()));
				splRelOpLogVO.setSignDescNm(signDescMap.get(splRelOpLogVO.getSignDesc()));
			}
		}
		listPage = new ListPageVO<SplRelOpLogVO>(list, searchListPage.getTotalPage());
		BaseLogUtils.newWebLogger("加载列表页面").setLogOperType(LogOperEnum.REQ)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
				.setWarning(false)
				.setKeys("listPage", JSON.toJSONString(listPage))
				.info();

		return listPage;
	}
	
	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");

		Long usrId = CurrentThreadContext.getCurrentUserId();
		if(StringUtils.isEmpty(usrId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("未获得当前登陆人信息！");
			return result;
		}
		String usrName = CurrentThreadContext.getCurrentUserName();

		String dataId = request.getParameter("dataId");//DATAID
		if(StringUtils.isEmpty(dataId)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("dataId不能为空！");
            return result;
		}
		String bizTypCd = request.getParameter("bizTypCd");//业务数据类型
		if(StringUtils.isEmpty(bizTypCd)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("业务数据类型不能为空！");
			return result;
		}

		//查询复议流程
		SysFlowSHQueryCondition flowCondition = new SysFlowSHQueryCondition();
		flowCondition.setSysCd(SplSystemConstant.FL_SYS_CD);
		flowCondition.setWordsInTheTable(bizTypCd.toUpperCase());
		flowCondition.setDataId(Long.valueOf(dataId));
		if (bizTypCd.equalsIgnoreCase(FlowStartRelInfoCfgEnum.FLOW_LNK_RISK_WARN.getWordsInTheTable())) {
			flowCondition.setBusTyp(FlowStartRelInfoCfgEnum.FLOW_LNK_RISK_WARN.getModelTyp());
		}
		if (bizTypCd.equalsIgnoreCase(FlowStartRelInfoCfgEnum.FLOW_SPL_RISK_WARN.getWordsInTheTable())) {
			flowCondition.setBusTyp(FlowStartRelInfoCfgEnum.FLOW_SPL_RISK_WARN.getModelTyp());
		}
		flowCondition.setStatus(BaseConstant.IS_YESNO_YES);
		List<SysFlowSHDTO> flowSHList = this.flowQueryApiService.searchFlowSHList(flowCondition);
		if (CollectionUtils.isNotEmpty(flowSHList)) {
			SysFlowSHDTO sysFlowSHDTO = flowSHList.get(0);
			if (!FlowConstant.FLOW_CHECK_STATE_PASS.equals(sysFlowSHDTO.getAudStsCd())) {
				BaseLogUtils.newWebLogger("已存在流程在审核中,不支持修改").setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
						.setWarning(false)
						.warn(LogExceptionEnum.COMMON_CODE_0002);

                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("已存在流程在审核中,不支持修改！");
                return result;
			}
		}

		SplRelOpLogVO entity = null;
		try {
			entity = this.getRequestParam(request);
			entity.setDataId(Long.valueOf(dataId));
			entity.setBizTypCd(bizTypCd);
			entity.setCrtTm(new Date());
			entity.setCrtUsrId(usrId);
			entity.setCrtUsrName(usrName);

			//TODO ADD PARAM
			Long id = this.splRelOpLogService.add(entity);
			result.setData(id);
			BaseLogUtils.newWebLogger("新增数据.[id="+id+"] DATA:" + JSONObject.toJSONString(entity)).setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.info();
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("新增对象失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.newWebLogger("新增对象失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		return result;
	}

	/**
	 * 批量新增
	 */
	@RequestMapping(value = "/addAll.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object addAll(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
		Long usrId = CurrentThreadContext.getCurrentUserId();
		if(StringUtils.isEmpty(usrId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("未获得当前登陆人信息！");
			return result;
		}
		String usrName = CurrentThreadContext.getCurrentUserName();

		String splIds = request.getParameter("splIds");
		String lnkIds = request.getParameter("lnkIds");
		List<SplRelOpLogVO> splOpLogRecVOS = new ArrayList<>();
		try {
			if(StringUtils.isNotEmpty(splIds)){
	            JSONArray idsArray = JSONArray.fromObject(splIds);
	            for (Object object : idsArray) {
	            	SplRelOpLogVO entity = this.getRequestParam(request);
	            	entity.setCrtTm(new Date());
	            	entity.setCrtUsrId(usrId);
	            	entity.setCrtUsrName(usrName);
	            	//splIdList.add(Long.valueOf(object.toString()));
	            	entity.setDataId(Long.valueOf(object.toString()));
					entity.setBizTypCd(SplRelLogBizTypCdNum.SPL.getBizTypCd());
					splOpLogRecVOS.add(entity);
	            }
				/*String[] splIdsStr = splIdList.split(";");
				if(splIdsStr.length>0){
					for (String str : splIdsStr) {
						entity.setDataId(Long.valueOf(str));
						entity.setBizTypCd(SplRelLogBizTypCdNum.SPL.getBizTypCd());
						splOpLogRecVOS.add(entity);
					}
				}*/
			}
			if(StringUtils.isNotEmpty(lnkIds)){
	            JSONArray idsArray = JSONArray.fromObject(lnkIds);
	            for (Object object : idsArray) {
	            	SplRelOpLogVO entity = this.getRequestParam(request);
	            	entity.setCrtTm(new Date());
	            	entity.setCrtUsrId(usrId);
	            	entity.setCrtUsrName(usrName);
	            	//lnkIdList.add(Long.valueOf(object.toString()));
	            	entity.setDataId(Long.valueOf(object.toString()));
					entity.setBizTypCd(SplRelLogBizTypCdNum.LNK.getBizTypCd());
					splOpLogRecVOS.add(entity);
	            }
				/*String[] lnkIdsStr = lnkIdList.split(";");
				if(lnkIdsStr.length>0){
					for (String str : lnkIdsStr) {
						entity.setDataId(Long.valueOf(str));
						entity.setBizTypCd(SplRelLogBizTypCdNum.LNK.getBizTypCd());
						splOpLogRecVOS.add(entity);
					}
				}*/
			}
			//TODO ADD PARAM
			boolean flag = this.splRelOpLogService.batchAdd(splOpLogRecVOS);
			BaseLogUtils.newWebLogger("新增数据. DATA:" + JSONObject.toJSONString(splOpLogRecVOS)).setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.info();
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("新增对象失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.newWebLogger("新增对象失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "修改成功!");

		Long usrId = CurrentThreadContext.getCurrentUserId();
		if(StringUtils.isEmpty(usrId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("未获得当前登陆人信息！");
			return result;
		}

		String id = request.getParameter("id");

		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("数据不存在!");
			BaseLogUtils.newWebLogger("修改数据,主键不存在.[id="+id+"]").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0001);
			return result;
		}
		String dataId = request.getParameter("dataId");//DATAID
		if(StringUtils.isEmpty(dataId)){
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "dataId不能为空.");
		}
		String bizTypCd = request.getParameter("bizTypCd");//业务数据类型
		if(StringUtils.isEmpty(bizTypCd)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("业务数据类型不能为空！");
			return result;
		}
		SplRelOpLogVO entity = null;
		try {
			entity = this.getRequestParam(request);
			entity.setId(Long.valueOf(id));
			entity.setDataId(Long.valueOf(dataId));
			entity.setBizTypCd(bizTypCd);
			entity.setMdfTm(new Date());
			entity.setMdfUsrId(usrId);
			//TODO ADD PARAM
			boolean success = this.splRelOpLogService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("修改失败!");
				BaseLogUtils.newWebLogger("修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity)).setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
						.setWarning(false)
						.warn(LogExceptionEnum.COMMON_CODE_0002);
			}
			BaseLogUtils.newWebLogger("修改成功.[id="+id+"] DATA:" + JSONObject.toJSONString(entity)).setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.info();
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("修改对象失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.newWebLogger("修改对象失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		
		return result;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeById.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "删除成功!");
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("主键不能为空!");
			return result;
		}
		try {
			this.splRelOpLogService.removeById(Long.valueOf(id));
			BaseLogUtils.newWebLogger("删除数据.[id="+id+"]").setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.info();

		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("移除对象失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.newWebLogger("移除对象失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		
		return result;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		String dataId = request.getParameter("dataId");
		if(StringUtils.isEmpty(dataId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("主键不能为空!");
			BaseLogUtils.newWebLogger("获取数据,主键不存在.[dataId="+dataId+"]").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0001);

			return result;
		}
		String bizTypCd = request.getParameter("bizTypCd");//业务数据类型
		if(StringUtils.isEmpty(bizTypCd)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("业务数据类型不能为空！");
			return result;
		}
		try {
			SplRelOpLogVO vo = null;
			SplRelOpLogQC qc = new SplRelOpLogQC();
			qc.setIsRiskSign(BaseConstant.IS_YESNO_YES);
			qc.setIsValid(BaseConstant.IS_YESNO_YES);
			qc.setIsDel(BaseConstant.IS_YESNO_NO);
			qc.setDataId(Long.valueOf(dataId));
			qc.setBizTypCd(bizTypCd);
			List<SplRelOpLogDTO> list = this.splRelOpLogService.searchList(qc);
			if(CollectionUtils.isNotEmpty(list)){
				vo = SplRelOpLogVOTransform.toVO(list.get(0));
			}
			result.setData(vo);
			BaseLogUtils.newWebLogger("获取数据.[dataId="+dataId+"]").setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.info();

		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.newWebLogger("根据主键获取对象失败,业务异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.newWebLogger("根据主键获取对象失败,系统异常").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
					.setWarning(false)
					.setThrowable(ex)
					.error(LogExceptionEnum.COMMON_CODE_0099);
		}
		
		return result;
	}

	/**
	 * 获取请求参数
	 * @param request 请求
	 * @return
	 */
	private SplRelOpLogVO getRequestParam(HttpServletRequest request) throws BaseException{
		//获取参数
		String isWarn = request.getParameter("isWarn");//是否预警
		String opTypCd = request.getParameter("opTypCd");//操作类型
		String signDesc = request.getParameter("signDesc");//标记原因（1:顶名购买，2:团单拆单，3:老赖，4:诈骗，5:法律纠纷，6:他人运营，7:私下转让，8:代收代付，99:其他  等 [SPL0052]）
		String opDesc = request.getParameter("opDesc");//操作描述

		/*if(StringUtils.isEmpty(isWarn)){
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "isWarn不能为空.");
		}*/
		if(StringUtils.isEmpty(opTypCd)){
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "标记类型不能为空.");
		}
		if(StringUtils.isEmpty(signDesc)){
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "标记原因不能为空.");
		}

		SplRelOpLogVO splRelOpLogVO = new SplRelOpLogVO();
		splRelOpLogVO.setOpTypCd(opTypCd);
		splRelOpLogVO.setSignDesc(signDesc);
		splRelOpLogVO.setOpDesc(opDesc);
		splRelOpLogVO.setIsDel(BaseConstant.IS_YESNO_NO);
		splRelOpLogVO.setIsNew(BaseConstant.IS_YESNO_YES);
		splRelOpLogVO.setIsRiskSign(BaseConstant.IS_YESNO_YES);
		splRelOpLogVO.setIsValid(BaseConstant.IS_YESNO_YES);
		if(StringUtils.isNotEmpty(isWarn)){
            splRelOpLogVO.setIsWarn(Integer.valueOf(isWarn));
        }
		splRelOpLogVO.setOpSource(SplSystemConstant.FL_WEB_CHL_CD);
		return splRelOpLogVO;
	}

}

